package dao

import (
	"time"

	"gorm.io/gorm"
)

// GetQuestionIDsByExamID 根据 examId 查询试题ID列表
func GetQuestionIDsByExamID(examId int) ([]int, error) {
	if DB == nil {
		return nil, gorm.ErrInvalidDB
	}
	var links []struct{ QuestionID int }
	if err := DB.Table("exam_exam_questions").Where("exam_id = ?", examId).Find(&links).Error; err != nil {
		return nil, err
	}
	var ids []int
	for _, l := range links {
		ids = append(ids, l.QuestionID)
	}
	return ids, nil
}

// ExamExamQuestions 考卷包含的题目列表
type ExamExamQuestions struct {
	ID         int        `gorm:"primaryKey" json:"id"`              // 主键ID
	ExamID     int        `gorm:"not null;index" json:"exam_id"`     // 考卷ID
	QuestionID int        `gorm:"not null;index" json:"question_id"` // 题目ID
	CreatedAt  *time.Time `gorm:"type:datetime" json:"created_at"`   // 关联时间
	UpdatedAt  *time.Time `gorm:"type:datetime" json:"updated_at"`   // 最后更新时间
}

// 表名称
func (ExamExamQuestions) TableName() string {
	return "exam_exam_questions"
}
